package emulator.GUI.keyboard;

import emulator.GUI.Dimension2D;
import emulator.hardware.io.peripherals.Button;
import emulator.hardware.io.peripherals.KeyboardMatrix;

public class VicKey implements Button {
	private String caption;
	private boolean is_toggle;
	private double pre_space;
	private Dimension2D<Double> size;
	private KeyboardMatrix matrix;
	private int a_index;
	private int b_index;
	
	public VicKey(String caption)
	{
		this.caption = caption;
		this.size = new Dimension2D<Double>(1.0, 1.0);
		this.pre_space = 0;
		this.is_toggle = false;
	}

	public VicKey(String caption, double width)
	{
		this.caption = caption;
		this.size = new Dimension2D<Double>(width, 1.0);
		this.pre_space = 0;
		this.is_toggle = false;
	}

	public VicKey(String caption, double width, double pre_space)
	{
		this.caption = caption;
		this.size = new Dimension2D<Double>(width, 1.0);
		this.pre_space = pre_space;
		this.is_toggle = false;
	}
	
	public VicKey(String caption, double width, boolean is_toggle)
	{
		this.caption = caption;
		this.size = new Dimension2D<Double>(width, 1.0);
		this.pre_space = 0;
		this.is_toggle = is_toggle;
	}

	public VicKey(String caption, double width, double pre_space, boolean is_toggle)
	{
		this.caption = caption;
		this.size = new Dimension2D<Double>(width, 1.0);
		this.pre_space = pre_space;
		this.is_toggle = is_toggle;
	}

	public VicKey attachToMatrix(KeyboardMatrix matrix, int a, int b)
	{
		this.matrix = matrix;
		this.a_index = a;
		this.b_index = b;
		return this;
	}
	
	/**
	 * @return the caption
	 */
	public String getCaption() {
		return caption;
	}

	/**
	 * @return the is_toggle
	 */
	public boolean isIsToggle() {
		return is_toggle;
	}

	/**
	 * @return the pre_space
	 */
	public double getPreSpace() {
		return pre_space;
	}

	/**
	 * @return the size
	 */
	public Dimension2D<Double> getSize() {
		return size;
	}

	/* (non-Javadoc)
	 * @see emulator.GUI.keyboard.Button#press()
	 */
	public void press() {
		if (matrix != null)
			matrix.keyDown(a_index, b_index);
	}

	/* (non-Javadoc)
	 * @see emulator.GUI.keyboard.Button#release()
	 */
	public void release() {
		if (matrix != null)
			matrix.keyUp(a_index, b_index);
	}
}
